﻿using System.ComponentModel.DataAnnotations;
using BankTransfer.Bank.Types.Enum;

namespace BankTransfer.Bank.Types.Types
{
    public class ExchangeRate
    {
        public decimal Rate { get; private set; }
        public Currency FromCurrency { get; private set; }
        public Currency TagetCurrency { get; private set; }

        public ExchangeRate(decimal rate, Currency fromCurrency, Currency tagetCurrency)
        {
            if (rate <= 0)
            {
                throw new ValidationException("ExchangeRate");
            }
            Rate = rate;
            FromCurrency = fromCurrency;
            TagetCurrency = tagetCurrency;
        }

        public Money ExchangeTo(Money targetMoney)
        {
            var amont = decimal.Divide(targetMoney.Amount, Rate);
            return new Money(amont, FromCurrency);
        }
    }
}